package fxification.java;

import com.sun.javafx.functions.Function1;

public class Utilities {
    private static void invokeFailureHandler (Function1<Void, ? super Throwable> onFailure, Throwable ex){
       if(onFailure != null){
           onFailure.invoke(ex);
       }
    }

    public static RuntimeException raiseFailure(Function1<Void, ? super Throwable> failureHandler, String msg){
        RuntimeException ex = new RuntimeException(msg);
        invokeFailureHandler(failureHandler, ex);
        return ex;
    }

    public static RuntimeException raiseFailure(Function1<Void, ? super Throwable> failureHandler, Throwable ex){
        invokeFailureHandler(failureHandler, ex);
        return new RuntimeException(ex);
    }
}
